﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MVC_Project.Model;
using MVC_Project.Bll.Goods;
using MVC_Project.Api.Models.MobileGoods;
using System.Drawing;
using System.Web.UI.WebControls;

namespace MVC_Project.Api.Areas.Goods
{
    public class MobileController : ApiController
    {
        GoodTypeBll tbll = new GoodTypeBll();
        // GET: api/Mobile
        public List<MobileGood> Get()
        {
            var goodtypes = tbll.GetMobileGoods();
            var data = from gt in goodtypes
                       select new MobileGood()
                       {
                           id = gt.id,
                           name = gt.name,
                           icon = gt.icon,
                           is_show_backstage = gt.is_show_backstage,
                           sort = gt.sort,
                           goods_list = from gd in gt.Good
                                        select new Models.MobileGoods.Goods()
                                        {
                                            id = gd.id,
                                            name = gd.name,
                                            content = gd.content,
                                            images = gd.images,
                                            use_spec = gd.use_spec,
                                            use_property = gd.use_property,
                                            unit = gd.unit,
                                            price = gd.price,
                                            sales = gd.sales,
                                            sort = gd.sort ,
                                            property = from pp in gd.GoodPropertyKey
                                                       select new GoodProperty() { 
                                                           id = pp.id,
                                                           name = pp.GoodSpecKey.name,
                                                           desc ="",
                                                           values = from pv in pp.GoodPropertyValue 
                                                                    select new PropertyValue() { 
                                                                        id = pv.id,
                                                                        code = pv.GoodSpecValue.code,
                                                                        value = pv.GoodSpecValue.value,
                                                                        is_default = pv.is_default
                                                                    }

                                                       }
                                        }

                       };

            var list = data.ToList();
            return list;


        }

        // GET: api/Mobile/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Mobile
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/Mobile/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/Mobile/5
        public void Delete(int id)
        {
        }
    }
}
